package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author hu hanSan
 * @Date 2024-09-06
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    /**
     * 条件分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        //执行数据库查询列表数据
        Page<NursingProjectVo> page = nursingProjectMapper.selectByPage(name, status);

        //封装PageResponse并返回
        PageResponse<NursingProjectVo> pageResponse = new PageResponse<>(page);
        //没有赋值，需手动赋值
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     */
    @Override
    public void insertNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.insertNursingProject(nursingProject);
    }

    /**
     * 根据id来查询护理项目
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo findNursingProjectById(Long id) {

       NursingProject nursingProject= nursingProjectMapper.selectById(id);
        NursingProjectVo projectVo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return projectVo;
    }

    /**
     * 修改护理项目
     *
     * @param nursingProjectDto
     */
    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);

    }

    /**
     * 启用和禁用
     *
     * @param id
     * @param status
     */
    @Override
    public void update(Long id, Integer status) {
        nursingProjectMapper.update(id,status);
    }

    /**
     * 根据id删除护理项目
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @Override
    public List<NursingProjectVo> selectAll() {

        //return BeanUtil.toBean(nursingProjectMapper.selectAll(dto),NursingProjectVo.class);
        List<NursingProjectVo>nursingProject = nursingProjectMapper.selectAll();
        return nursingProject;

    }
}
